package.cpath = package.cpath .. ';C:/Users/win/AppData/Roaming/JetBrains/IdeaIC2020.3/plugins/intellij-emmylua/classes/debugger/emmy/windows/x86/?.dll'
local dbg = require('emmy_core')
dbg.tcpConnect('localhost', 9966)

package.path = package.path .. ";C:/Users/win/Documents/_lua/util/?.lua"

local Set = require("Set")

function Test1()
    local s = Set.new()
    assert(0 == s:GetCount())

    s:Add("1")
    assert(1 == s:GetCount())
    assert(true == s:Contains("1"))
    assert(false == s:Contains("0"))

    s:Add("1")
    assert(1 == s:GetCount())
    assert(true == s:Contains("1"))
    assert(false == s:Contains("0"))

    s:Add("2")
    assert(2 == s:GetCount())
    assert(true == s:Contains("2"))
    assert(false == s:Contains("0"))

    s:Add("3")
    assert(3 == s:GetCount())
    assert(true == s:Contains("3"))
    assert(false == s:Contains("0"))

    s:Add("4")
    assert(4 == s:GetCount())
    assert(true == s:Contains("4"))
    assert(false == s:Contains("0"))

    s:Remove("1")
    assert(3 == s:GetCount())
    assert(true == s:Contains("4"))
    assert(false == s:Contains("1"))

    s:Remove("2")
    assert(2 == s:GetCount())
    assert(true == s:Contains("3"))
    assert(false == s:Contains("2"))

    s:Clear()
    assert(0 == s:GetCount())
    assert(false == s:Contains("3"))
    assert(false == s:Contains("2"))
end
Test1()

function S1ClearAndAdd123(s1, s2)
    s1:Clear()
    assert(false == s1:IsOverlaps(s2))

    s1:Add("1")
    s1:Add("2")
    s1:Add("3")

    assert(s1:IsOverlaps(s2))
end

function Test2()
    local s1 = Set.new()
    assert(0 == s1:GetCount())

    s1:Add("1")
    s1:Add("2")
    s1:Add("3")

    local s2 = Set.new()
    s2:Add("3")
    s2:Add("4")
    s2:Add("5")

    s1:IntersectWith(s2)
    assert(1 == s1:GetCount())
    assert(true == s1:Contains("3"))

    S1ClearAndAdd123(s1, s2)

    s1:Clear()
    s1:Add("1")
    s1:Add("2")
    s1:Add("3")

    s1:UnionWith(s2)
    assert(5 == s1:GetCount())
    assert(false == s1:Contains("0"))
    assert(true == s1:Contains("5"))

    S1ClearAndAdd123(s1, s2)

    s1:ExceptWith(s2)
    assert(2 == s1:GetCount())
    assert(false == s1:Contains("0"))
    assert(true == s1:Contains("1"))

    S1ClearAndAdd123(s1, s2)

    local s4 = Set.new()
    s4:Add("1")
    s4:Add("2")
    s4:Add("3")
    s4:Add("4")

    assert(s1:IsSubsetOf(s1))
    assert(s1:IsSubsetOf(s4))
    assert(false == s1:IsProperSubsetOf(s1))
    assert(true == s1:IsProperSubsetOf(s4))

    assert(s1:IsSupersetOf(s1))
    assert(s4:IsSupersetOf(s1))

    assert(false == s1:IsProperSupersetOf(s1))
    assert(s4:IsProperSupersetOf(s1))

    assert(false == s1:IsEquals(s4))
end
Test2()


function Test3()
    local a = {"a"}
    local b = {"b"}
    local c = {"c"}
    local d = {"d"}

    local s1 = Set.new()
    s1:Add(a)
    s1:Add(b)
    s1:Add(c)
    assert(3 == s1:GetCount())
    assert(false == s1:Contains(d))
    assert(true == s1:Contains(a))
    assert(true == s1:Contains(b))
    assert(true == s1:Contains(c))
    --assert(true == s1:Contains({"a"}))

    local s2 = Set.new()
    s2:Add(a)
    s2:Add(b)
    s2:Add(c)
    s2:Add(d)

    --local s3 = { {"a"}, {"b"}, {"c"},}
end
Test3()


